package com.example.shangjiqi;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.shangjiqi.R;

public class ProfileEditActivity extends AppCompatActivity {

    private Button btnBack;
    private TextView tvUsernameDisplay;
    private TextView tvInterest;
    private String username;
    public static final int REQUEST_INTEREST = 100; // 兴趣选择页请求码

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_edit);

        btnBack = findViewById(R.id.btn_back);
        tvUsernameDisplay = findViewById(R.id.tv_username_display);
        tvInterest = findViewById(R.id.tv_interest);

        // 接收首页传递的用户名
        Intent intent = getIntent();
        username = intent.getStringExtra("username");
        if (username != null) {
            tvUsernameDisplay.setText("用户名：" + username);
        }

        // 返回按钮：关闭当前页
        btnBack.setOnClickListener(v -> finish());

        // 兴趣文本框：点击跳转到兴趣选择页
        tvInterest.setOnClickListener(v -> {
            Intent intent1 = new Intent(ProfileEditActivity.this, InterestSelectActivity.class);
            startActivityForResult(intent1, REQUEST_INTEREST);
        });
    }

    // 接收兴趣选择页的返回结果
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_INTEREST && resultCode == RESULT_OK) {
            if (data != null) {
                String interest = data.getStringExtra("interest");
                if (interest != null && !interest.isEmpty()) {
                    tvInterest.setText("兴趣：" + interest);
                }
            }
        }
    }
}